<?php
namespace App\APi\Controllers;

use App\Api\Models\ShoppingCard;
use App\Http\Controllers\Controller;
use App\Api\Services\JsonService;
use Illuminate\Http\Request;
use App\Api\Repositories\ShoppingCardRepositorie;

class ShoppingCardController extends Controller
{
    /**
     * @param Request $request
     * @return array
     */
    public function getAddShopping(Request $request)
    {

        $validate = $request->validate([
            'goods_id' => 'required|after:num',
            'sku_id' =>'required|after:num',
        ]);

        $shoppingCardData = ShoppingCardRepositorie::getCardAdd($validate);

        if($shoppingCardData){
            return JsonService::success($shoppingCardData);
        }
        return JsonService::fail('添加失败');
    }

    public function getShoppingCard($goods_id)
    {
        $allowField = [
            'id',
            'goods_id',
            'goods_name',
            'goods_image',
            'price'
        ];

        $CardData = ShoppingCard::getCardList($goods_id,$allowField);

        if($CardData){
            return JsonService::success($CardData);
        }
        return JsonService::fail('查询数据为空');
    }
}